<?php
namespace app\mobile\model;

/**
 * Class AdType
 * @package app\mobile\model     广告分类表
 */
class AdType extends BaseModel
{
    /*
     * 查找某个分类广告
     */
    public function get_ad($type)
    {
        $map['id'] = $type;
        $map['status'] = 1;
        $adArr = $this->where($map)
            ->with(['ad'=>function($query){
                $int['start_time'] = ['lt', time()];
                $int['end_time'] = ['gt', time()];
                $query
                    ->where($int)
                    ->limit(5)
                    ->order(['sort'=>'desc','create_time'=>'desc'])
                    ->field('id,parenTid,picUrl,linkUrl,skip_type');
            }])
            ->find();
        return $adArr;
    }
    /*
     * 分类和广告一对多
     */
    public function ad()
    {
        return $this->hasMany('Ad','parenTid','id');
    }
}